home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / education / evo / evo.c < prev    next >
C/C++ Source or Header  |  1992-10-30  |  21KB  |  721 lines

  1.  
  2. #include "INCLUDE:Lattice/math.h"
  3. #include "INCLUDE:Lattice/stdio.h"
  4. #include "INCLUDE:exec/types.h"
  5. #include "INCLUDE:graphics/gfx.h"
  6. #include "INCLUDE:graphics/gfxmacros.h"
  7. #include "INCLUDE:exec/exec.h"
  8. #include "INCLUDE:exec/execbase.h"
  9. #include "INCLUDE:graphics/view.h"
  10. #include "INCLUDE:graphics/gfxbase.h"
  11. #include "INCLUDE:exec/libraries.h"
  12. #include "INCLUDE:intuition/intuition.h"
  13. #include "INCLUDE:graphics/text.h"
  14.  
  15. struct  NewScreen  ns;
  16. struct  NewWindow  nw;
  17.  
  18. struct  Screen     *evo_screen;
  19. struct  Window     *evo_window, *map_window, *text_window;
  20.  
  21. struct  RastPort   *rp, *rp2;
  22. struct  ViewPort   *vp;
  23.  
  24. struct  IntuiMessage  *message;
  25.  
  26. struct  TextAttr       Ruby_Eight;
  27. struct  TextFont       *fontptr;
  28.  
  29. struct  GfxBase       *GfxBase;
  30. struct  IntuitionBase *IntuitionBase;
  31. struct  Library       *DiskfontBase;
  32.  
  33. SHORT   hominid;
  34. SHORT   hominid_index[621];
  35.  
  36. int     i, j, x, y, oldx, class, code, rc, color, parity;
  37. int     delta_t, delta_x, delta_y, s, fossil_index;
  38. int     point, selected_box;
  39. BOOL    button_is_down, first_pass;
  40.  
  41. UBYTE   profile[ 621 ][ 52 ][ 2 ];
  42.  
  43. int     SetUpEvographics(), DrawMap(), DisplayText();
  44.  
  45. #include "evo_species.include"
  46. #include "evo_data.include"
  47. #include "evo_africa.include"
  48. #include "evo_text.include"
  49.  
  50. /*---------------------------------------*/
  51. /*                                       */
  52. /*             //  Evo  //               */
  53. /*                                       */
  54. /*    A human evolution demonstration    */
  55. /*        program for the Amiga          */
  56. /*                                       */
  57. /*            Steve Bonner               */
  58. /*            August 1987                */
  59. /*                                       */
  60. /*---------------------------------------*/
  61.  
  62. main()
  63. {
  64.   register int k;
  65.  
  66. GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  67. IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
  68.  
  69. if( (GfxBase == NULL) || (IntuitionBase == NULL)) exit();
  70.  
  71. DiskfontBase = OpenLibrary("diskfont.library",0);
  72. if ( DiskfontBase == NULL ) exit();
  73.  
  74.  
  75. SetUpEvographics();
  76.  
  77. SetDrMd( rp, JAM2 );
  78. SetAPen( rp, 2 );
  79.  
  80. RectFill( rp, 45, 20, 295, 120 );
  81. Move( rp, 110, 55 );
  82.  
  83. SetAPen( rp, 7 );
  84. SetBPen( rp, 2 );
  85. Text( rp, "(please wait)", 13 );
  86.  
  87. SetAPen( rp, 2 );
  88. SetBPen( rp, 0 );
  89.  
  90. Move( rp,  20, 140 );
  91. Draw( rp, 620, 140 );
  92.  
  93. for ( i = 0; i <= 20; i++)        {
  94.   Move( rp, gradation[i], 138 );
  95.   Draw( rp, gradation[i], 142 );  }
  96.  
  97. Move( rp, 9, 137 );
  98. Text( rp,
  99.   "20            10            5   4   3      2        1  ", 55 );
  100. Move( rp, 9, 152 );
  101. Text( rp,
  102.   "        Miocene         Pliocene            Pleistocene", 55 );
  103.  
  104. Move( rp, 325, 45 )    ;
  105. Text( rp, "Genus       ", 12 );
  106. Move( rp, 325, 60 )    ;
  107. Text( rp, "Species     ", 12 );
  108. Move( rp, 325, 75 )    ;
  109. Text( rp, "Subspecies  ", 12 );
  110. Move( rp, 325, 90 )    ;
  111. Text( rp, "Mill yrs ago", 12 );
  112.  
  113. Move( rp, 435, 45 );
  114. Text( rp, ":",  1 );
  115. Move( rp, 435, 60 );
  116. Text( rp, ":",  1 );
  117. Move( rp, 435, 75 );
  118. Text( rp, ":",  1 );
  119. Move( rp, 435, 90 );
  120. Text( rp, ":",  1 );
  121.  
  122.  
  123. /* Draw the boxes to surround user options:  */
  124. for ( k = 0; k < 5; k++)           {
  125.   SetAPen( rp, 3 );
  126.   RectFill( rp, 20 + k * 122, 172, 132 + k * 122, 192 );
  127.   SetAPen( rp, 6 );
  128.   Move( rp,  20 + k * 122 , 172 );
  129.   Draw( rp, 132 + k * 122 , 172 );
  130.   Draw( rp, 132 + k * 122 , 192 );
  131.   Draw( rp,  20 + k * 122 , 192 );
  132.   Draw( rp,  20 + k * 122 , 172 ); }
  133.  
  134. SetDrMd( rp, JAM1 );
  135. Move( rp, 20, 185 );
  136. /*  Here are the various options:  */
  137. Text( rp,
  138.    "    Help         Text          Map        Glossary      Notes",
  139.    61 );
  140.  
  141. SetAPen( rp, 2 );
  142. SetDrMd( rp, JAM2 );
  143.  
  144. x = 0;
  145. y = 1;
  146.  
  147. /*  The cranium for each hominid species consists of 52 points    */
  148. /*  which define its outline.  Here we are copying the outlines   */
  149. /*  of the nine known hominids into our working array, 'profile'  */
  150. for ( i = 0; i <= 51; i++) {
  151.   j = 2*i;
  152.   k = j+1;
  153.  
  154.   profile[  20 ][ i ][ x ] = proconsul_profile[ j ];
  155.   profile[  20 ][ i ][ y ] = proconsul_profile[ k ];
  156.   profile[ 147 ][ i ][ x ] = kenyapith_profile[ j ];
  157.   profile[ 147 ][ i ][ y ] = kenyapith_profile[ k ];
  158.   profile[ 333 ][ i ][ x ] = afarensis_profile[ j ];
  159.   profile[ 333 ][ i ][ y ] = afarensis_profile[ k ];
  160.   profile[ 360 ][ i ][ x ] = africanus_profile[ j ];
  161.   profile[ 360 ][ i ][ y ] = africanus_profile[ k ];
  162.   profile[ 403 ][ i ][ x ] = habilis_profile  [ j ];
  163.   profile[ 403 ][ i ][ y ] = habilis_profile  [ k ];
  164.   profile[ 439 ][ i ][ x ] = erectus_profile  [ j ];
  165.   profile[ 439 ][ i ][ y ] = erectus_profile  [ k ];
  166.   profile[ 554 ][ i ][ x ] = esapiens_profile [ j ];
  167.   profile[ 554 ][ i ][ y ] = esapiens_profile [ k ];
  168.   profile[ 611 ][ i ][ x ] = neander_profile  [ j ];
  169.   profile[ 611 ][ i ][ y ] = neander_profile  [ k ];
  170.   profile[ 620 ][ i ][ x ] = msapiens_profile [ j ];
  171.   profile[ 620 ][ i ][ y ] = msapiens_profile [ k ];  }
  172.  
  173.  
  174. /*  Interpolate between known hominid forms:   */
  175. for ( i = PROCONSUL; i <= NEANDER; i++)  {
  176.   delta_t = fossil_dates[i+1] - fossil_dates[i];
  177.   fossil_index = fossil_dates[i];
  178.  
  179.   Forbid();
  180.  
  181.   /* Now consider each point along the profile: */
  182.   for ( j = 0; j <= 51; j++ ) {
  183.  
  184.     delta_x = profile[ fossil_dates[i+1] ][ j ][ x ] -
  185.               profile[ fossil_index      ][ j ][ x ] ;
  186.     delta_y = profile[ fossil_dates[i+1] ][ j ][ y ] -
  187.               profile[ fossil_index      ][ j ][ y ] ;
  188.     s = 1;
  189.  
  190.     /*  Here we do the linear interpolation.                         */
  191.     /*  (I interpolate on the logarithmic scale, since it's easier.) */
  192.     for ( k = fossil_dates[i]+1; k < fossil_dates[i+1]; k++)        {
  193.       profile[ k ][ j ][ x ] = profile[ fossil_index ][ j ][ x ] +
  194.               s * delta_x / delta_t;
  195.       profile[ k ][ j ][ y ] = profile[ fossil_index ][ j ][ y ] +
  196.               s * delta_y / delta_t;
  197.       s++;
  198.                                                                     }
  199.                            }  /*  j  */
  200.     /* Let's give our disk drive a chance to catch up: */
  201.     Permit();
  202.                            }  /*  i  */
  203.  
  204.  
  205.  
  206. button_is_down = FALSE;
  207.  
  208. oldx = 403;
  209. SetAPen( rp, 1 );
  210. WritePixel( rp, oldx, 140 );
  211. hominid = 4;
  212.  
  213. Move( rp, 460, 45 );
  214. Text( rp, genera[ hominid ], 18 );
  215. Move( rp, 460, 60 );
  216. Text( rp, species[ hominid ], 18 );
  217. Move( rp, 460, 90 );
  218. Text( rp, yearstring[oldx], 6 );
  219.  
  220.  
  221. /*  Hominid_divisions allows us to rapidly map an x-coordinate    */
  222. /*  into its corresponding hominid form (an integer from 0 to 8)  */
  223. hominid = 8;
  224. for (i = 620; i >= 20; i--)   {
  225.   if ( i < hominid_divisions[ hominid ] ) hominid--;
  226.   hominid_index[i] = hominid; }
  227.  
  228. color = 8;
  229.  
  230. hominid = 4;
  231. first_pass = TRUE;
  232.  
  233. Forbid();
  234.  
  235. while ( 1 == 1) {
  236.  
  237.   if (first_pass == FALSE )    {
  238.     WaitPort( evo_window -> UserPort );
  239.     message = GetMsg( evo_window -> UserPort );
  240.  
  241.     class = message -> Class;
  242.     code  = message -> Code;
  243.     x     = message -> MouseX;
  244.     y     = message -> MouseY;
  245.  
  246.     ReplyMsg( message );       }
  247.  
  248.   else                         {
  249.     class = 0;
  250.     code  = SELECTUP;
  251.     x     = oldx;
  252.     y     = 140;
  253.     first_pass = FALSE;        }
  254.  
  255.  
  256.   if ( class == CLOSEWINDOW )   {
  257.     CloseWindow( evo_window );
  258.     CloseScreen( evo_screen );
  259.     exit();                     }
  260.  
  261.   if ( code == SELECTDOWN ) {
  262.  
  263.     point = ReadPixel( rp, x, y );
  264.  
  265.     /*  Is our current pixel a 'user-option' color?. . .  */
  266.     if ( (point == 3) || (point == 6) ) {
  267.       selected_box = (x - 10)/122;
  268.  
  269.       if (selected_box == 2)
  270.         DrawMap();
  271.       else
  272.         DisplayText();
  273.  
  274.       goto NoSkull;                     }
  275.  
  276.     button_is_down = TRUE;
  277.     color = 8;              }
  278.  
  279.   if ( code == SELECTUP   ) button_is_down = FALSE;
  280.  
  281.   if ( (button_is_down) || (code == SELECTUP) )   {
  282.  
  283.     if ((x >= 20) && (x <= 620)) {
  284.     SetAPen( rp, 2 );
  285.     WritePixel( rp, oldx, 140 );
  286.     SetAPen( rp, 1 );
  287.     WritePixel( rp,    x, 140 );
  288.     oldx = x;
  289.  
  290.     /*  If the species has changed, update the labels:  */
  291.     if ( hominid != hominid_index[x] )       {
  292.       hominid = hominid_index[x];
  293.  
  294.       Move( rp, 460, 45 );
  295.       Text( rp, genera[ hominid ], 18 );
  296.       Move( rp, 460, 60 );
  297.       Text( rp, species[ hominid ], 18 );
  298.       Move( rp, 460, 75 );
  299.       Text( rp, subspecies[ hominid ], 18 ); }
  300.  
  301.     Move( rp, 460, 90 );
  302.